/**
 * @author: 善良的YWJ
 * @Created by shanliangdeYWJ on 2022/02/17
 * @file: index.js
 * @description:
 * ==================
 * [参考](https://github.com/apollographql/starwars-server/)
 * ==================
 * @link [Github](https://github.com/shanliangdeYWJ)
 */


var express = require('express')

// [参考]（https://github.com/APIs-guru/graphql-voyager/issues/87#issuecomment-426771723
var { express: voyagerMiddleware } = require('graphql-voyager/middleware')

var { graphqlHTTP } = require('express-graphql')
const schema = require('./schema')

var app = express()

app.get('/', (req, res) => {
  res.end(`
    <a href="/api/graphql">/api/graphql</a>
    <a href="/voyager">/voyager</a>
  `)
})


app.use('/api/graphql', graphqlHTTP({
  schema: schema,
  graphiql: true // 是否开启调试界面，true是开启，false是不开启
}))

app.use('/voyager', voyagerMiddleware({ endpointUrl: '/api/graphql' }))

app.listen(8002, () => console.log('server is run on http://localhost:8002'))